/*
 * timer.c
 *
 *  Created on: 2013. 10. 16.
 *      Author: jphong
 */

#include	"np.h"

struct timeval *timer = NULL;		/* active timer */

/* Start a timer */
void start_timer(unsigned int msec )
{
	static struct timeval interval, now, timeout;		/* timeout in time of day */

	if ( msec <= 0 ) {
		timer = NULL;			// ignore
	}
	if ( gettimeofday( &now, NULL ) < 0 )
		error( 1, errno, "timeout: gettimeofday failure" );
	interval.tv_sec = msec / 1000;
	interval.tv_usec = ( msec % 1000) * 1000;
	timeradd( &now, &interval, &timeout );
	timer = &timeout;
	debug("Timer started\n");
	return;
}

/* cancel a timer */
void stop_timer()
{
	timer = NULL;
	debug("Timer stopped\n");
	return;
}
